package com.atguigu.d_tcp_plus;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.InetAddress;
import java.net.Socket;

public class Client { //客户端
    public static void main(String[] args) throws IOException {
        //创建客户端对象
        Socket socket = new Socket(InetAddress.getLocalHost(),10010);

        //创建流对象
        OutputStream os = socket.getOutputStream();


        //使用通讯的流对象 写数据 -> 给服务器发数据
        os.write("你好 ! TCP !!".getBytes());

        //客户端接收回显
        InputStream is = socket.getInputStream();

        byte[] bys = new byte[1024];
        int len = is.read(bys);

        //字节数组转换成字符串
        String back = new String(bys, 0, len);
        System.out.println("服务器回显信息 : " + back);

        //关闭资源
        //socket.close();
    }
}
